package com.zrrd.mcl.product.controller;

import com.zrrd.mcl.common.result.Result;
import com.zrrd.mcl.product.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/product/test")
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("/testLock")
    public Result testLock() throws InterruptedException {
        testService.testLock();
        return Result.ok();
    }

    //测试读写锁中读的操作
    @GetMapping("/read")
    public Result read() {
        String msg = testService.readLock();
        return Result.ok(msg);
    }

    //测试读写锁中写的操作
    @GetMapping("/write")
    public Result write() {
        String msg = testService.writeLock();
        return Result.ok();
    }

}
